/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */

import { Module } from '@ohos/hvigor';

import { CoreModuleModelImpl } from '../../model/module/core-module-model-impl.js';
import { ProjectModel } from '../../model/project/project-model.js';

/**
 * PluginBuilder的公共基类
 *
 * @since 2023/02/01
 */
export class CorePluginBuilder {
  protected readonly module: Module;

  constructor(module: Module) {
    this.module = module;
  }

  public createModuleModel(projectModel: ProjectModel, isHapModule: boolean): CoreModuleModelImpl {
    const moduleModel = projectModel.getModuleModelByName(this.module.getName()) as CoreModuleModelImpl;

    // module build-profile.json5 schema check,尽量先进行schema check再执行后续逻辑
    moduleModel.moduleBuildProfileCheck(isHapModule);

    // 处理target的默认配置行为
    moduleModel.processTargetsConfig();
    return moduleModel;
  }
}
